#ifndef __FILESYSTEM_H__
#define __FILESYSTEM_H__

#define FS_IOMAN_DEVICES 16
#define FS_IOMANX_DEVICES 32

#include <dirent.h>

typedef enum
{
	FM_READ,
	FM_WRITE,
} FileMode;

typedef struct FSContext
{
	char m_Path[256];
	int m_iFile;
	DIR* m_pDir;
	char m_List[256];
} FSContext;

typedef enum
{
	FT_FILE,
	FT_DIRECTORY,
	FT_LINK,
} FileType;

typedef struct FSFileInfo
{
	struct
	{
		int			m_iYear;
		int			m_iMonth;
		int			m_iDay;
		int			m_iHour;
		int			m_iMinute;
	} m_TS; // time stamp

	FileType	m_eType;	
	int				m_iProtection; // 3 bits protection per section: UrwxGrwxOrwx

	int				m_iSize;
	char			m_Name[256];
} FSFileInfo;

void FileSystem_Create( FSContext* pContext );
void FileSystem_Destroy( FSContext* pContext );
int FileSystem_OpenFile( FSContext* pContext, const char* pFile, FileMode eMode, int iContinue );
int FileSystem_OpenDir( FSContext* pContext, const char* pDir );
int FileSystem_ReadFile( FSContext* pContext, char* pBuffer, int iSize );
int FileSystem_WriteFile( FSContext* pContext, const char* pBuffer, int iSize );
int FileSystem_ReadDir( FSContext* pContext, FSFileInfo* pInfo );
void FileSystem_Close( FSContext* pContext );
void FileSystem_BuildPath( char* pResult, const char* pOriginal, const char* pAdd );
int FileSystem_ChangeDir( FSContext* pContext, const char* pPath );
int FileSystem_DeleteFile( FSContext* pContext, const char* pFile );
int FileSystem_CreateDir( FSContext* pContext, const char* pDir );

#endif
